package com.dly.hope.dao;

import com.dly.hope.modle.*;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author linyu.dai
 * @project myserve
 * @description
 * @creat 2022/11/1 13:14:32
 */
@Repository
public class PermissionsDao extends BaseDao{

    private static final QAccountRole accountRole = QAccountRole.accountRole;

    private static final QRolePermissions rolePermissions = QRolePermissions.rolePermissions;

    public QPermissions basePath(){
        return QPermissions.permissions;
    }


    public List<Permissions> getPermissions(String accountId){
        return queryFactory.selectFrom(basePath())
                .leftJoin(rolePermissions).on(basePath().id.eq(rolePermissions.permissionId).and(efficient(rolePermissions.dataStatus)))
                .leftJoin(accountRole).on((rolePermissions.roleId.eq(accountRole.roleId)).and(efficient(accountRole.dataStatus)))
                .where(efficient(basePath().dataStatus).and(accountRole.accountId.eq(accountId))).fetch();
    }
}
